//
//  CRBBoxHomeHttp.m
//  ChampsARotate
//
//  Created by 吴凡 on 2018/12/21.
//  Copyright © 2018 Logan.Fan. All rights reserved.
//

#import "CRBBoxHomeHttp.h"
#import "SSGAFSimpleTool.h"
#define kAPI_BRAND_LIST @"/app/goods/searchConditions" //品牌列表
#define kAPI_SERIES_LIST @"/app/goods/series/" //系列列表
#define kAPI_GOODS_LIST @"/app/goods" //型号列表
#define kAPI_TOPIC_LIST @"/app/user-subjects/page" //话题列表
#define kAPI_TOPIC_LIST_EXPIRE @"/app/user-subjects/page/expired"//过期话题列表
#define kAPI_TOPIC_DETAIL_UGC_LIST @"/app/ugc/list-by-user-subjectid"//话题详情ugc列表
#define kAPI_TOPIC_DETAIL @"/app/user-subjects/" // 话题详情
#define kAPI_TASK_INFO @"/app/user/task-detail/" // 首页调，是否满足7天活动要求
#define kAPI_TASK_REGIST @"/app/user/account-info" // 注册完后，弹出活动窗口
#define kAPI_TASK_ISSHOW @"/app/user-task-detail/update-show-red-package/"





@implementation CRBBoxHomeHttp

#pragma mark - 品牌系列型号
+ (void)requestBrandListData:(ResponseSuccess)success fail:(ResponseFail)fail {
    
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_BRAND_LIST];
    
    [[SSGAFSimpleTool sharedManager]GET:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            CRBBrandListModel *brandListModel = [CRBBrandListModel yy_modelWithJSON:responseObject[@"data"]];
            [brandListModel.brandInfo iterateThroughsDataToFindHotBrand]; // 把热门数据遍历、整合
            success(task,brandListModel);
            
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
         fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}

+ (void)requestSeriesListDataWithBrandId:(NSString *)brandId :(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_SERIES_LIST];

    NSString *url = [NSString stringWithFormat:@"%@/%@",str,brandId?brandId:@""];
    
    [[SSGAFSimpleTool sharedManager]GET:url params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            NSMutableArray *dataSource = [NSMutableArray new];
            for (NSDictionary *seriesDic in responseObject[@"data"]) {
                CRBSeriesInfoModel *seriesInfoModel = [CRBSeriesInfoModel yy_modelWithDictionary:seriesDic];
                [dataSource addObject:seriesInfoModel];
            }
            success(task,dataSource);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}

//BrandId:(NSString *)brandId
//brandId?brandId:@""

+ (void)requestGoodsListDataWithseriesId:(NSString *)seriesId brandId:(NSString*)brandId :(ResponseSuccess)success fail:(ResponseFail)fail{
    
    NSString *page = @"1";
    NSString *size = @"1000";
    NSString *sort = @"searchCount,desc";
//    NSDictionary *patameter = @{@"page":page,@"size":size,@"sort":sort,@"series":seriesId?seriesId:@""};
    NSString *seriesIdStr = seriesId?seriesId:@"";
    NSString *brandIdsStr = brandId?brandId:@"";

    
    
    NSDictionary *patameter = @{@"page":page,@"size":size,@"sort":sort,@"seriesIds":@[seriesIdStr],@"brandIds":@[brandIdsStr]};
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_GOODS_LIST];

    [[SSGAFSimpleTool sharedManager] POST:str params:patameter success:^(NSURLSessionDataTask *task, id responseObject) {
        NSMutableArray *dataSource = [NSMutableArray new];
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            for (NSDictionary *data in responseObject[@"data"][@"goodVOs"]) {
                goodVOsModel *goodModel = [goodVOsModel yy_modelWithDictionary:data];
                [dataSource addObject:goodModel];
            }
            success(task,dataSource);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
    
}

#pragma mark - 话题列表
/* 话题列表*/
+ (void)requestTopicListWithPage:(NSNumber *)page size:(NSNumber *)size success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TOPIC_LIST];

    NSDictionary *patameter = @{@"page":page,@"size":size};
    [[SSGAFSimpleTool sharedManager] POST:str params:patameter success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            MainTopicModel *mainTopicModel = [MainTopicModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,mainTopicModel);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 话题列表-已过期
/* 话题列表 已过期*/
+ (void)requestExpiredTopicListWithPage:(NSNumber *)page size:(NSNumber *)size success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSDictionary *patameter = @{@"page":page,@"size":size};
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TOPIC_LIST_EXPIRE];

    [[SSGAFSimpleTool sharedManager] POST:str params:patameter success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            MainTopicModel *mainTopicModel = [MainTopicModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,mainTopicModel);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 话题详情UGC列表
/* 话题详情UGC列表*/
+ (void)requestTopicDetailUgcListWithPage:(NSNumber *)page size:(NSNumber *)size sort:(NSNumber *)sort topicId:(NSString *)topicId success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TOPIC_DETAIL_UGC_LIST];

    NSDictionary *patameter = @{@"page":page,@"size":size,@"sort":sort,@"userSubjectId":topicId};
    [[SSGAFSimpleTool sharedManager] POST:str params:patameter success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            TopicDetailModel *topicDetailModel = [TopicDetailModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,topicDetailModel);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 话题详情info
/* 话题详情info*/
+ (void)requestTopicDetailWithId:(NSString *)topicId success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TOPIC_DETAIL];

    [[SSGAFSimpleTool sharedManager] GET:[NSString stringWithFormat:@"%@%@",str,topicId] params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            TopicDetailModel *topicDetailModel = [TopicDetailModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,topicDetailModel);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 是否达到7天活动要求
+ (void)request7daysTaskWithUserId:(NSString *)userId success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TASK_INFO];

    [[SSGAFSimpleTool sharedManager] GET:[NSString stringWithFormat:@"%@?userId=%@",str,userId] params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            TaskModel *model = [TaskModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,model);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 注册完活动弹窗
+ (void)requestTaskAfterRegistWithUserId:(NSString *)userId success:(ResponseSuccess)success fail:(ResponseFail)fail {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TASK_REGIST];

    [[SSGAFSimpleTool sharedManager] GET:[NSString stringWithFormat:@"%@?userId=%@",str,userId] params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"]isEqualToString:@"00"]) {
            TaskModel *model = [TaskModel yy_modelWithDictionary:responseObject[@"data"]];
            success(task,model);
        } else {
            fail(task,nil,responseObject[@"code"],responseObject[@"msg"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
#pragma mark - 上报服务器已经展示过活动toast
+ (void)requestIsShowTaskToast {
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.lj,kAPI_TASK_ISSHOW];

    [[SSGAFSimpleTool sharedManager] POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {

        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
      //  fail(task,error,nil,@"请求失败，请检测网络连接");
    }];
}
@end
